package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.model.DidCadastro;
import br.com.vti.sisp_sicrim.antigo.model.Idclc001;
import br.com.vti.sisp_sicrim.antigo.model.SicControle;
import br.com.vti.sisp_sicrim.antigo.model.Sisll001;
import br.com.vti.sisp_sicrim.antigo.model.Tablele;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela
 * Idcpc005Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Idcpc005Report {
	private String nomeClasse;
	private String nomide;
	private String cabecaCet;
	private String nroPagina;
	private String cabecaSeg;
	private String cabecaIde;
	private int dataCorrente;
	private String poldir; // DB
	private String inddir; // DB
	private String meddir; // DB
	private String anudir; // DB
	private String mindir; // DB
	private String polesq; // DB
	private String indesq; // DB
	private String medesq; // DB
	private String anuesq; // DB
	private String minesq; // DB
	private Long regger; // DB
	private Integer numpos; // DB
	public String maodir;
	public String maoesq;
	private String horaCorrente;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	DidCadastro vwDidcad = new DidCadastro();
	SicControle vwDvecon = new SicControle();
	// Classes includes
	Idclc001 idclc001 = new Idclc001();
	Sisll001 sisll001 = new Sisll001();
	Tablele tablele = new Tablele();

	public Idcpc005Report() throws JRException, ParseException {
		inicializar();
	}

	public Idcpc005Report(Sessao sessao) throws JRException, ParseException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException, ParseException {
		report = new Relatorios();
		nomeClasse = this.getClass().getSimpleName();
		nomide = "";
		dataCorrente = 0;
		cabecaCet = "SECRETARIA DE ESTADO DA SEGURAN�A PUBLICA";
		cabecaSeg = "SECRETARIA DE ESTADO DA SEGURAN�A PUBLICA";
		cabecaIde = "INSTITUTO DE IDENTIFICACAO CIVIL - IIC";
		horaCorrente = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()); // *TIMX
		report.setNumeroRel(1, "C");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", " ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 4);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "*");
				report.adicionaCampo(3, 70, "Cabecacet", "X", "ZZZ.Z99", "");
				report.adicionaCampo(118, 6, "lit_118_6", "C", "", "PAGINA");
				report.adicionaCampo(127, 5, "nroPagina", "S", "ZZZ.Z99", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 3);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "*");
				report.adicionaCampo(3, 60, "Cabecaseg", "X", "", "");
				report.adicionaCampo(118, 15, "lit_118_15", "C", "", "RELAT. IDCPCA05");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(4, 4);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "*");
				report.adicionaCampo(3, 50, "Cabecaide", "X", "99/99/9999", "");
				report.adicionaCampo(118, 4, "lit_118_4", "C", "", "DATA");
				report.adicionaCampo(125, 8, "dataCorrente", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(5, 1);
			{
				report.adicionaCampo(1, 45, "lit_1_45", "C", "", "* SISTEMA DE INFORMACOES DE SEGURANCA PUBLICA");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(6, 2);
			{
				report.adicionaCampo(1, 63, "lit_1_63", "C", "", "* RELACAO DAS PESSOAS CADASTRADAS NO INSTITUTO DE IDENTIFICACAO");
				report.adicionaCampo(65, 32, "lit_65_32", "C", "", "CIVIL PELA FORMULA DATILOSCOPICA");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(7, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(8, 5);
			{
				report.adicionaCampo(1, 19, "lit_1_19", "C", "", "FORMATO MAO DIREITA");
				report.adicionaCampo(41, 20, "lit_41_20", "C", "", "FORMATO MAO ESQUERDA");
				report.adicionaCampo(81, 8, "lit_81_8", "C", "", "R. GERAL");
				report.adicionaCampo(96, 5, "lit_96_5", "C", "", "POSTO");
				report.adicionaCampo(102, 37, "lit_102_37", "C", "", "NOME DA PESSOA IDENTIFICADA NO I.I.C.");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(9, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(2, "D");
		{
			report.setNumeroLinhaRel(1, 13);
			{
				report.adicionaCampo(1, 7, "poldir", "X", "", "");
				report.adicionaCampo(9, 7, "inddir", "X", "", "");
				report.adicionaCampo(17, 7, "meddir", "X", "", "");
				report.adicionaCampo(25, 7, "anudir", "X", "", "");
				report.adicionaCampo(33, 7, "mindir", "X", "", "");
				report.adicionaCampo(41, 7, "polesq", "X", "", "");
				report.adicionaCampo(49, 7, "indesq", "X", "", "");
				report.adicionaCampo(57, 7, "medesq", "X", "", "");
				report.adicionaCampo(65, 7, "anuesq", "X", "", "");
				report.adicionaCampo(73, 7, "minesq", "X", "", "");
				report.adicionaCampo(81, 13, "regger", "N", "", "");
				report.adicionaCampo(96, 3, "numpos", "N", "", "");
				report.adicionaCampo(102, 35, "Nomide", "X", "", "");
				report.setFimLinhaRel();
			}
		}
		setCabecacet(cabecaCet);
		setCabecaseg(cabecaSeg);
		setCabecaide(cabecaIde);
		setHoraCorrente(horaCorrente);
	}

	public boolean validar() {
		return true;
	}

	public String getNomeClasse() {
		return nomeClasse;
	}

	public void setNomeClasse(String nomeClasse) throws ParseException {
		this.nomeClasse = nomeClasse;
		report.adicionaValorReport("Program", nomeClasse);
	}

	public String getNomide() {
		return nomide;
	}

	public void setNomide(String nomide) throws ParseException {
		this.nomide = nomide;
		report.adicionaValorReport("Nomide", nomide);
	}

	public String getCabecacet() {
		return cabecaCet;
	}

	public void setCabecacet(String cabecaCet) throws ParseException {
		this.cabecaCet = cabecaCet;
		report.adicionaValorReport("Cabecacet", cabecaCet);
	}

	public String getCabecaseg() {
		return cabecaSeg;
	}

	public void setCabecaseg(String cabecaSeg) throws ParseException {
		this.cabecaSeg = cabecaSeg;
		report.adicionaValorReport("Cabecaseg", cabecaSeg);
	}

	public String getCabecaide() {
		return cabecaIde;
	}

	public void setCabecaide(String cabecaIde) throws ParseException {
		this.cabecaIde = cabecaIde;
		report.adicionaValorReport("Cabecaide", cabecaIde);
	}

	public int getDataCorrente() {
		return dataCorrente;
	}

	public void setDataCorrente(int dataCorrente) throws ParseException {
		this.dataCorrente = dataCorrente;
		report.adicionaValorReport("dataCorrente", dataCorrente);
	} // /

	public String getMaodir() {
		return this.poldir + this.inddir + this.meddir + this.anudir + this.mindir;
	}

	public void setMaodir(String maodir) throws ParseException {
		this.maodir = maodir;
		this.poldir = UtilBean.subStr(maodir, 0, 7);
		report.adicionaValorReport("Poldir", UtilBean.subStr(maodir, 0, 7));
		this.inddir = UtilBean.subStr(maodir, 7, 7);
		report.adicionaValorReport("Inddir", UtilBean.subStr(maodir, 7, 7));
		this.meddir = UtilBean.subStr(maodir, 14, 7);
		report.adicionaValorReport("Meddir", UtilBean.subStr(maodir, 14, 7));
		this.anudir = UtilBean.subStr(maodir, 21, 7);
		report.adicionaValorReport("Anudir", UtilBean.subStr(maodir, 21, 7));
		this.mindir = UtilBean.subStr(maodir, 28, 7);
		report.adicionaValorReport("Mindir", UtilBean.subStr(maodir, 28, 7));
	} // /

	public String getMaoesq() {
		return this.polesq + this.indesq + this.medesq + this.anuesq + this.minesq;
	}

	public void setMaoesq(String maoesq) throws ParseException {
		this.maoesq = maoesq;
		this.polesq = UtilBean.subStr(maoesq, 0, 7);
		report.adicionaValorReport("Polesq", UtilBean.subStr(maoesq, 0, 7));
		this.indesq = UtilBean.subStr(maoesq, 7, 7);
		report.adicionaValorReport("Indesq", UtilBean.subStr(maoesq, 7, 7));
		this.medesq = UtilBean.subStr(maoesq, 14, 7);
		report.adicionaValorReport("Medesq", UtilBean.subStr(maoesq, 14, 7));
		this.anuesq = UtilBean.subStr(maoesq, 21, 7);
		report.adicionaValorReport("Anuesq", UtilBean.subStr(maoesq, 21, 7));
		this.minesq = UtilBean.subStr(maoesq, 28, 7);
		report.adicionaValorReport("Minesq", UtilBean.subStr(maoesq, 28, 7));
	}

	public String getNroPagina() {
		return nroPagina;
	}

	public void setNroPagina(String nroPagina) throws ParseException {
		this.nroPagina = nroPagina;
		report.adicionaValorReport("nroPagina", nroPagina);
	}

	public String getHoraCorrente() {
		return horaCorrente;
	}

	public void setHoraCorrente(String horaCorrente) throws ParseException {
		this.horaCorrente = horaCorrente;
		report.adicionaValorReport("horaCorrente", horaCorrente);
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		setNroPagina(String.valueOf(report.getPageNumber()));
		report.gravaRelatorio(report, nroRel, false);
	}

	public void imprimir() throws FileNotFoundException, JRException {
		report.imprimir();
	}

	public Long getRegger() {
		return regger;
	}

	public void setRegger(Long regger) throws ParseException {
		this.regger = regger;
		report.adicionaValorReport("regger", regger);
	}

	public Integer getNumpos() {
		return numpos;
	}

	public void setNumpos(Integer numpos) throws ParseException {
		this.numpos = numpos;
		report.adicionaValorReport("numpos", numpos);
	}

	public String getAnudir() {
		return anudir;
	}

	public void setAnudir(String anudir) throws ParseException {
		this.anudir = anudir;
		report.adicionaValorReport("Anudir", anudir);
	}

	public String getAnuesq() {
		return anuesq;
	}

	public void setAnuesq(String anuesq) throws ParseException {
		this.anuesq = anuesq;
		report.adicionaValorReport("Anuesq", anuesq);
	}

	public String getInddir() {
		return inddir;
	}

	public void setInddir(String inddir) throws ParseException {
		this.inddir = inddir;
		report.adicionaValorReport("Inddir", inddir);
	}

	public String getIndesq() {
		return indesq;
	}

	public void setIndesq(String indesq) throws ParseException {
		this.indesq = indesq;
		report.adicionaValorReport("Indesq", indesq);
	}

	public String getMeddir() {
		return meddir;
	}

	public void setMeddir(String meddir) throws ParseException {
		this.meddir = meddir;
		report.adicionaValorReport("Meddir", meddir);
	}

	public String getMedesq() {
		return medesq;
	}

	public void setMedesq(String medesq) throws ParseException {
		this.medesq = medesq;
		report.adicionaValorReport("Medesq", medesq);
	}

	public String getMindir() {
		return mindir;
	}

	public void setMindir(String mindir) throws ParseException {
		this.mindir = mindir;
		report.adicionaValorReport("Mindir", mindir);
	}

	public String getMinesq() {
		return minesq;
	}

	public void setMinesq(String minesq) throws ParseException {
		this.minesq = minesq;
		report.adicionaValorReport("Minesq", minesq);
	}

	public String getPoldir() {
		return poldir;
	}

	public void setPoldir(String poldir) throws ParseException {
		this.poldir = poldir;
		report.adicionaValorReport("Poldir", poldir);
	}

	public String getPolesq() {
		return polesq;
	}

	public void setPolesq(String polesq) throws ParseException {
		this.polesq = polesq;
		report.adicionaValorReport("Polesq", polesq);
	}

}
